import {
	baseUrl
} from './baseUrl.js'
import {
	login
}
from '@/api/index.js'
const serve = (params) => {
	return new Promise((reslove, reject) => {
		uni.showLoading({
			title: "加载中"
		})
		uni.request({
			url: baseUrl + params.url,
			method: params.method || 'get',
			data: params.data,
			header: {
				'Authorization': 'Bearer ' + uni.getStorageSync('token') || '',
			},
			success: res => {
				if (res.statusCode == 401) {
					uni.showToast({
						title: "登录已过期",
						icon: "error",
						duration: 1000
					})
					uni.setStorageSync('token', '')
					setTimeout(() => {
						uni.reLaunch({
							url: "/pageLogin/Login"
						})

					}, 1500)
					return
				} else if (res.statusCode == 203) {
					uni.showToast({
						title: "暂未登录",
						icon: "error",
						duration: 1000
					})
					uni.setStorageSync('token', '')
					setTimeout(() => {
						uni.reLaunch({
							url: "/pages/login/index"
						})
					}, 1500)
					return
				} else if (res.statusCode == 403) {
					uni.hideLoading()
					uni.showToast({
						title: '您的帐号已经被冻结',
						icon: "none",
						duration: 1000
					})
					return
				}
				reslove(res.data)
				uni.hideLoading()
			},
			fail: error => {
				reject(error)
				uni.hideLoading()
			}
		})
	})
}
export default serve